package ch.msoftch.gui.utils.popup.actions;

import org.eclipse.jdt.core.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.ui.*;
import org.eclipse.ui.part.*;
import ch.msoftch.gui.utils.*;

/**
 * Action used to create property constants for a java bean.<br>
 * This action is registred for the java editor.
 * 
 * @author hautle
 */
public class CreatePropertyFieldsEditorAction implements IEditorActionDelegate {
    /** The editor. */
    private IEditorPart editor;

    /**
     * {@inheritDoc}
     */
    @Override
    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
        editor = targetEditor;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void run(IAction action) {
        try {
            PropertyClassEnhancer.enhanceClass(JavaCore.createCompilationUnitFrom(((FileEditorInput) editor.getEditorInput()).getFile()));
        } catch (JavaModelException e) {
            EclipseHelper.showError(editor.getSite().getShell(), "Error while enhancing the class", e);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void selectionChanged(IAction action, ISelection selection) {
    }
}
